http: create header field names as internalized strings#64277
http: create header field names as internalized strings#64277araujogui wants to merge 2 commits into
Conversation
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
|
Review requested:
|
There was a problem hiding this comment.
Pull request overview
This PR optimizes HTTP header processing by internalizing header field name strings so repeated header names can compare faster (e.g., in JS matchKnownFields()) and reduce duplicate string allocations when building req.headers.
Changes:
- Add
StringPtr::ToInternalizedString()to create V8 internalized strings from header field names. - Use internalized strings for header field names when constructing the headers array passed to JS.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
| return String::NewFromOneByte(env->isolate(), | ||
| reinterpret_cast<const uint8_t*>(str_), | ||
| NewStringType::kInternalized, | ||
| size_) |
There was a problem hiding this comment.
hmm.. I'm not convinced this is a good idea.
While it certainly helps legitimate cases, there's a risk here.
A malicious sender could leverage this into a memory leak or cause significant additional GC pressure pretty easily by sending a large number of intentionally different header values at a high rate. Internalized strings do get cleaned up during a major GC. The current existing non-internalized strings can be cleaned up in a minor GC.
We really ought to be internalizing only known header names.
There was a problem hiding this comment.
You're right, should I apply the same fix on the HTTP/2 path?
node/src/node_http_common-inl.h
Line 126 in 8e1ab55
Internalize header field names so repeated occurrences resolve to the same string in the isolate's string table, speeding up
matchKnownFields()comparisons andreq.headersbuilds.Benchmark